cellForRowAtIndexPath: crashes when trying to access the indexPath.row/[indexPath row]
Posted
by Emil
on Stack Overflow
See other posts from Stack Overflow
or by Emil
Published on 2010-05-30T09:38:56Z
Indexed on
2010/05/30
9:42 UTC
Read the original article
Hit count: 517
Hey.
I am loading in data to a UITableView
, from a custom UITableViewCell
(own class and nib). It works great, until I try to access the indexPath.row
/[indexPath.row]
.
I'll post my code first, it will probably be easier for you to understand what I mean then.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"CustomCell";
CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil){
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
for (id currentObject in topLevelObjects){
if ([currentObject isKindOfClass:[CustomCell class]]){
cell = (CustomCell *) currentObject;
break;
}
}
}
NSLog(@"%@", indexPath.row);
// Configure the cell...
NSUInteger row = indexPath.row;
cell.titleLabel.text = [postsArrayTitle objectAtIndex:indexPath.row];
cell.dateLabel.text = [postsArrayDate objectAtIndex:indexPath.row];
cell.cellImage.image = [UIImage imageWithContentsOfFile:[postsArrayImg objectAtIndex:indexPath.row]];
NSLog(@"%@", indexPath.row);
return cell;
}
The odd thing is, it does work when it loads in the first three cells (they are 125px high), but crashes when I try to scroll down.
The indexPath
is always avaliable, but not the indexPath.row
, and I have no idea why it isn't!
Please help me.. Thanks.
Additional error code:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x5d10c20'
*** Call stack at first throw:
(
0 CoreFoundation 0x0239fc99 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x024ed5de objc_exception_throw + 47
2 CoreFoundation 0x023a17ab -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x02311496 ___forwarding___ + 966
4 CoreFoundation 0x02311052 _CF_forwarding_prep_0 + 50
5 MyFancyAppName 0x00002d1c -[HomeTableViewController tableView:cellForRowAtIndexPath:] + 516
[...])
© Stack Overflow or respective owner